package com.cyl.h5.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cyl.external.WechatUtil;
import com.cyl.h5.domain.form.ActivityPickupCouponCallBackForm;
import com.cyl.h5.domain.form.WechatLoginForm;
import com.cyl.manager.act.service.CouponActivityService;
import com.cyl.manager.act.service.MemberCouponService;
import com.cyl.manager.ums.domain.query.MemberQuery;
import com.cyl.manager.ums.service.MemberWechatService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisService;

import cn.hutool.crypto.digest.DigestUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *  火山回调
 */
@RestController
@RequestMapping("")
public class VolcengineCallBackController {

//	@Autowired
//    private CouponActivityService couponActivityService;
//    @Autowired
//    private RedisService redisService;
//    /**
//     * 当观众在观看页领取卡券时，企业直播会对所设置的接口地址进行回调通知。
//     * @return
//     */
//    @GetMapping("/no-auth/activityPickupCoupon/callBack")
//    public ResponseEntity<Boolean> activityPickupCouponCallBack(@RequestBody ActivityPickupCouponCallBackForm query) {
//    	String AccountSecret = "123";
//    	String AccountId = query.getAccountId();
//    	String ActivityId = query.getActivityId();
//    	String CouponId = query.getCouponId();
//    	String EventType = query.getEventType();
//    	String ExternalUserId = query.getExternalUserId();
//    	String Id = query.getId();
//    	String ThirdPartyId = query.getThirdPartyId();
//    	String UserId = query.getUserId();
//    	String SignKey = AccountSecret+AccountId+ActivityId+CouponId+EventType+ExternalUserId+Id+ThirdPartyId+UserId;
//		String SignMy = DigestUtil.md5Hex(SignKey);
//    	String SignHs = query.getSign();
//    	if(!SignMy.equals(SignHs)) {
//            throw new RuntimeException("签名不匹配！");
//    	}
//    	if(!"ActivityPickupCouponCallBack".equals(EventType)) {
//    		throw new RuntimeException("回调EventType不正确");
//    	}
//    	
//    	Long id = Long.parseLong(Id);
//    	Long memberId = Long.parseLong(ExternalUserId);
//    	String redisKey = "h5_receive_coupon" + id;
//        String redisValue = id + "_" + System.currentTimeMillis();
//        try {
//            redisService.lock(redisKey, redisValue, 60);
//            return ResponseEntity.ok(couponActivityService.receiveCoupon(id,memberId));
//        } catch (Exception e) {
//            throw new RuntimeException(e.getMessage());
//        } finally {
//            try {
//                redisService.unLock(redisKey, redisValue);
//            } catch (Exception e) {
//
//            }
//        }
//    	
//    }
     
}
